using System.Collections.Generic;
using UnityEngine;

namespace Gj
{
    public static class UserCustomTools
    {
        private static readonly UserCustomSettings.Item[] list;

        static UserCustomTools()
        {
            var settings = LoadSettings();
            list = settings.customs;
        }

        private static UserCustomSettings LoadSettings()
        {
            var loadedSettings = (UserCustomSettings)Resources.Load("UserCustomSettings", typeof(UserCustomSettings));
            if (loadedSettings == null)
            {
                loadedSettings = ScriptableObject.CreateInstance<UserCustomSettings>();
                Debug.LogError("UserCustomSettings is not exist (Resources)");
            }

            return loadedSettings;
        }

        public static UserCustomSettings.Item[] GetAll()
        {
            return list;
        }

        public static int Get(string key)
        {
            if (key == "") return -1;
            for (int i = 0; i < list.Length; i++)
            {
                if (key == list[i].key) return list[i].value;
            }
            return -1;
        }
    }
}